<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学习记录统计</title>
    <link rel="icon" href="favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="css/styles.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        :root {
            --primary-color: #165DFF;
            --secondary-color: #14B8A6;
            --accent-color: #8B5CF6;
            --text-color: #1F2937;
            --text-secondary: #6B7280;
            --bg-color: #F9FAFB;
            --card-bg: #FFFFFF;
            --border-color: #E5E7EB;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            --gradient-bg: linear-gradient(135deg, #F5F7FF 0%, #E4E7FF 100%);
        }

        body {
            background: var(--gradient-bg);
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
            color: var(--text-color);
            margin: 0;
            padding: 0;
        }

        .stats-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .chart-container {
            margin-bottom: 30px;
            background-color: var(--card-bg);
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 20px;
            border: 1px solid var(--border-color);
            transition: all 0.3s ease;
        }

        /* 移动设备适配 */
        @media (max-width: 768px) {
            .chart-container {
                padding: 15px;
                margin-bottom: 20px;
            }
            
            .chart-container canvas {
                height: 220px !important;
            }
            
            .summary-cards {
                flex-direction: column;
                gap: 15px;
            }
            
            .summary-card {
                padding: 16px;
            }
            
            h1 {
                font-size: 24px;
            }
            
            h2 {
                font-size: 18px;
            }
        }

        .chart-container:hover {
            box-shadow: 0 10px 30px rgba(22, 93, 255, 0.15);
            transform: translateY(-3px);
        }

        canvas {
            max-width: 100%;
            height: 250px !important;
        }

        .stats-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        .back-btn {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 500;
            transition: all 0.2s ease;
            display: flex;
            align-items: center;
            gap: 8px;
            box-shadow: 0 4px 14px rgba(22, 93, 255, 0.4);
        }

        .back-btn:hover {
            background-color: #0E4CDE;
            transform: translateY(-2px);
            box-shadow: 0 6px 18px rgba(22, 93, 255, 0.5);
        }

        .summary-cards {
            display: flex;
            justify-content: space-between;
            margin-bottom: 30px;
            flex-wrap: wrap;
            gap: 20px;
        }

        .summary-card {
            background-color: var(--card-bg);
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 24px;
            flex: 1;
            min-width: 220px;
            margin: 0;
            border: 1px solid var(--border-color);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .summary-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 4px;
            height: 100%;
        }

        .summary-card:nth-child(1)::before {
            background-color: var(--secondary-color);
        }

        .summary-card:nth-child(2)::before {
            background-color: var(--primary-color);
        }

        .summary-card:nth-child(3)::before {
            background-color: var(--accent-color);
        }

        .summary-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 12px 20px rgba(0, 0, 0, 0.12);
        }

        .summary-card h3 {
            margin-top: 0;
            color: var(--text-secondary);
            font-size: 16px;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .summary-card .value {
            font-size: 32px;
            font-weight: 700;
            margin: 12px 0;
            background: linear-gradient(135deg, var(--text-color) 0%, var(--text-secondary) 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .summary-card .label {
            font-size: 14px;
            color: var(--text-secondary);
            margin-top: 8px;
            display: block;
        }

        .header-content {
            background-color: var(--card-bg);
            padding: 20px 30px;
            border-radius: 12px;
            box-shadow: var(--shadow);
            margin-bottom: 30px;
            border: 1px solid var(--border-color);
        }

        h1 {
            color: var(--primary-color);
            font-size: 28px;
            margin-bottom: 10px;
            font-weight: 700;
        }

        h2 {
            color: var(--text-color);
            font-size: 22px;
            margin-bottom: 20px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        h2::before {
            content: '';
            display: inline-block;
            width: 8px;
            height: 24px;
            background-color: var(--primary-color);
            border-radius: 4px;
        }

        footer {
            text-align: center;
            padding: 20px;
            color: var(--text-secondary);
            font-size: 14px;
            margin-top: 40px;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <div class="header-content">
                <h1>学习记录统计</h1>
                <div class="stats-header">
                    <button class="back-btn" onclick="window.location.href='index.html'">返回练习</button>
                </div>
            </div>
        </header>

        <main class="stats-container">
            <div class="summary-cards">
                <div class="summary-card">
                    <h3>总学习时间</h3>
                    <div class="value" id="totalTime">0 分钟</div>
                    <div class="label">所有学习记录的总时间</div>
                </div>
                <div class="summary-card">
                    <h3>总学习数量</h3>
                    <div class="value" id="totalAttempts">0 题</div>
                    <div class="label">所有学习记录的题目总数</div>
                </div>
                <div class="summary-card">
                    <h3>平均正确率</h3>
                    <div class="value" id="averageAccuracy">0%</div>
                    <div class="label">所有学习记录的平均正确率</div>
                </div>
            </div>

            <div class="chart-container">
                <h2>学习统计综合图表</h2>
                <canvas id="combinedChart"></canvas>
            </div>
        </main>

        <footer>
            <p>英语句子听力练习 | 学习统计</p>
        </footer>
    </div>

    <script src="js/stats.js"></script>
    <script>
        // 页面加载完成后初始化统计图表
        document.addEventListener('DOMContentLoaded', function() {
            // 绘制合并图表
            LearningStats.drawCombinedChart('combinedChart');

            // 更新汇总统计
            updateSummaryStats();
        });

        // 更新汇总统计信息
        function updateSummaryStats() {
            // 获取最近7天的统计数据
            const stats = LearningStats.getRecent7DaysStats();

            // 计算总学习时间
            const totalTimeMinutes = stats.reduce((sum, item) => sum + item.totalTimeMinutes, 0);
            document.getElementById('totalTime').textContent = totalTimeMinutes + ' 分钟';

            // 计算总学习数量
            const totalAttempts = stats.reduce((sum, item) => sum + item.totalAttempts, 0);
            document.getElementById('totalAttempts').textContent = totalAttempts + ' 题';

            // 计算平均正确率
            const totalCorrect = stats.reduce((sum, item) => sum + item.correctAttempts, 0);
            const averageAccuracy = totalAttempts > 0 ? 
                Math.round((totalCorrect / totalAttempts) * 100) : 0;
            document.getElementById('averageAccuracy').textContent = averageAccuracy + '%';
        }
    </script>
</body>
</html>